package com.czyxy.repository;

import com.czyxy.domain.StudentFee;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by mike on 6/9/17.
 */
public interface StudentFeeRepository extends JpaRepository<StudentFee,Integer> {
    @Query("select o from StudentFee o where o.studentCode=?1 and o.studentName=?2 order by o.feeDate desc ")
    public Page<StudentFee> findAllByStudentCodeAndStudentName(String studentCode,String studentName,Pageable pageable);
    public List<StudentFee> findAllByClassCode(String classCode);

    public List<StudentFee> findAllByTeacherCode(String teacherCode);

    @Query("select o from StudentFee o where (o.classCode like %:classCode% or o.className like %:className%)" +" and o.studentCode like %:studentCode% and o.studentName like %:studentName% and (:qf=false or o.adjustAmount<0) order by o.studentName asc, o.feeDate desc")
    Page<StudentFee> teacherQuery(
            @Param("classCode") String classCode,
            @Param("className") String className,
            @Param("studentCode") String studentCode,
            @Param("studentName") String studentName,
            @Param("qf") boolean qf,
            Pageable pageable
    );


}
